import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import legacy from '@vitejs/plugin-legacy'
import path from 'path' // 关键代码
// https://vitejs.dev/config/
export default ({ mode }) => {
  const env = loadEnv(mode, process.cwd());

  return defineConfig({
    plugins: [vue(),
      legacy({
        targets:['chrome 52'],  // 需要兼容的目标列表，可以设置多个
        additionalLegacyPolyfills:['regenerator-runtime/runtime'] // 面向IE11时需要此插件
      })],
    resolve: {
      alias: {
        // 关键代码
        '@': path.resolve(__dirname, './src')
      }
    },
    // build: {
    //   target: ['chrome52'],
    //   cssTarget: ["chrome52"],
    // },
    server: {
      proxy: {
        [env.VITE_APP_BASE_API]: {
          target: env.VITE_APP_SERVICE_URL,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, '')
        }
      },
      open: true
    },
  })
}